import request from '@/axios'
import type { ListParams, Response } from '@/api/api'

export interface Row {
  id?: number
  name: string
  img: []
  unit: string
  money: number
  purchasing_price: number
  weight: number
  shelf_life: number
  descriptions: string
  goods_cate_id_one: number
  goods_cate_id_two: number
  spec_type: number
  attrs: {}
  specs: {
    spec_name: any
    money: any
    weight: any
    purchasing_price: any
    img: any
  }[]
}

export interface RowDetail {
  id?: number
  name: string
  img: []
  unit: string
  money: number
  purchasing_price: number
  weight: number
  shelf_life: number
  descriptions: string
  goods_cate_id_one: number
  goods_cate_id_two: number
  spec_type: number
  attrs: {}
  specs: {
    spec_name: any
    money: any
    weight: any
    purchasing_price: any
    img: any
  }[]
}

export interface FormData {
  id?: number
  name: string
  img: []
  unit: string
  money: number
  purchasing_price: number
  weight: number
  shelf_life: number
  descriptions: string
  goods_cate_id_one: number
  goods_cate_id_two: number
  spec_type: number
  attrs: {}
  specs: {
    spec_name: any
    money: any
    weight: any
    purchasing_price: any
    img: any
  }[]
  spec: {
    spec_name: any
    money: any
    weight: any
    purchasing_price: any
    img: any
  }[]
  goods_rule: string[]
}
// 商品列表
export const getListApi = (data: ListParams): Promise<Response<Row>> => {
  return request.post({ url: '/goods/list', data })
}
// 商品列表新增
export const createApi = (data: Partial<FormData>): Promise<IResponse> => {
  return request.post({ url: '/goods/create', data })
}
// 商品列表详情
export const getDetailApi = (data: { id: number }): Promise<Response<RowDetail>> => {
  return request.post({ url: '/goods/details', data })
}

// 商品列表状态修改
export const updateStatusApi = (data: { status: string; id: string }): Promise<IResponse> => {
  return request.post({ url: '/goods/modify_status', data })
}
// 商品列表编辑
export const modifyApi = (data: Partial<FormData>): Promise<IResponse> => {
  return request.post({ url: '/goods/modify', data })
}
// 商品列表删除
export const delApi = (data: { id: string }): Promise<IResponse> => {
  return request.post({ url: '/goods/del', data })
}

// 商品列表检索框
export const getSelectListApi = (data: ListParams): Promise<Response<Row>> => {
  return request.post({ url: '/goods/select', data })
}
